﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using GestorDocument.ViewModel;
using MahApps.Metro.Controls;
using Microsoft.Reporting.WinForms;

namespace GestorDocument.UI.Reportes
{
    /// <summary>
    /// Lógica de interacción para ReporteAsuntosPendientesView.xaml
    /// </summary>
    public partial class ReporteAsuntosPendientesView : MetroWindow
    {
        public List<ReportParameter> Parametros;
        public ReporteAsuntosPendientesView()
        {
            InitializeComponent();

            this.DataContext = new ReporteAsuntosPendientesViewModel();
        }

        private ReporteAsuntosPendientesViewModel GetViewModel()
        {
           return  this.DataContext as ReporteAsuntosPendientesViewModel;
        }

        private void btnFiltro_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                this._reportViewer.Clear();
                this._reportViewer.RefreshReport();
                this._reportViewer.Refresh();
                Microsoft.Reporting.WinForms.ReportDataSource reportDataSource = new Microsoft.Reporting.WinForms.ReportDataSource();
                Microsoft.Reporting.WinForms.ReportDataSource reportDataSource2 = new Microsoft.Reporting.WinForms.ReportDataSource();
                GestorDocument.DAL.Reportes.GestorDocumentDataSet dataset = new DAL.Reportes.GestorDocumentDataSet();
                reportDataSource.Name = "DataSetAsuntosPendientes";
                reportDataSource2.Name = "DataSetAsuntosTurnadosDG";
                
                //refrescar los datos
                GetViewModel().GetDestinatarios();
                //mandarle los parametros
                this.GetParametros();

                reportDataSource.Value = dataset.GetAsuntosPendientesDG;
                reportDataSource2.Value = dataset.GetAsuntosTurnadosDG;

                this._reportViewer.LocalReport.DataSources.Clear();
                this._reportViewer.LocalReport.DataSources.Add(reportDataSource);
                this._reportViewer.LocalReport.DataSources.Add(reportDataSource2);
                this._reportViewer.LocalReport.ReportPath = "Reportes\\ReportAsuntosPendientesDG.rdlc";
                this._reportViewer.LocalReport.SetParameters(Parametros);
                GestorDocument.DAL.Reportes.GestorDocumentDataSetTableAdapters.GetAsuntosPendientesDGTableAdapter adapter = new DAL.Reportes.GestorDocumentDataSetTableAdapters.GetAsuntosPendientesDGTableAdapter();
                GestorDocument.DAL.Reportes.GestorDocumentDataSetTableAdapters.GetAsuntosTurnadosDGTableAdapter adapter2 = new DAL.Reportes.GestorDocumentDataSetTableAdapters.GetAsuntosTurnadosDGTableAdapter();
                adapter.Fill(dataset.GetAsuntosPendientesDG,GetViewModel().SelectedDest);
                adapter2.Fill(dataset.GetAsuntosTurnadosDG, GetViewModel().SelectedDest);
                this._reportViewer.RefreshReport();


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
        public void GetParametros()
        {
            this.Parametros = new List<ReportParameter>();
            try
            {
                this.Parametros.Add(new ReportParameter("FechaRevision", string.Format("{0:dd/MM/yyyy}", DateTime.Now))); 
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }
    }
}
